
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {


    $('#collect').click(function(){
        layer.confirm(__("当用户量过多时,归集时间久，确定一键归集")+'?',{icon:1,btn:[__('yes'),__('no')],btnAlign:'c',title:__('title')},function(index){
            document.getElementById("collect").innerHTML="归集中·······";
            $.ajax({
                url: 'user/user/allCollect',
                type:'POST',
                dataType: 'json',
                success: function(data){
                    document.getElementById("collect").innerHTML=data.msg;
                    document.getElementById("collect").innerHTML="一键归集";
                    layer.alert(data.msg);


                    // layer.msg(data.msg);
                },
                error:function(err){
                    console.log(err);
                }
            });

            layer.close(index);
        },function(){
            //取消
        });

    });

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/index',
                    add_url: 'user/user/add',
                    edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                columns: [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'detail.tjid', title: __('推荐人id'), operate: false},
                        //{field: 'detail.realname', title: __('Realname'), operate: 'LIKE'},
                        //{field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        //{field: 'level', title: __('Level'), operate: 'LIKE'},
                        {field: 'tronAddr', title: __('tron地址'), operate: 'LIKE'},
                        {field: 'credit1', title: __('质押数量'), operate: 'LIKE'},
                        {field: 'credit2', title: __('历史充值数量'), operate: 'LIKE'},
                        {field: 'credit6', title: __('可直接提数量'), operate: false},
                        {field: 'status', title: __('状态'), operate: false},
                        //{field: 'team_usdt', title: __('累加团队投资金额'), operate: 'LIKE'},
                        //{field: 'lock_credit1', title: __('锁定FC'), operate: 'LIKE'},
                        //{field: 'lock_credit2', title: __('冻结USDT'), operate: 'LIKE'},
                        //{field: 'sf_lock_credit1', title: __('身份升级锁定FC'), operate: 'LIKE'},
                        //{field: 'lock_jdjl', title: __('冻结收益'), operate: 'LIKE'},
                        //{field: 'recommend_code', title: __('Recommend ID'), operate: 'LIKE'},
                        // {field: 'detail.cash_url', title: __('cash_url'), operate: 'LIKE'},

                        // {field: 'eth', title: __('ETH Amount'), operate:'BETWEEN'},
                        //{field: 'credit3acd', title: __('ETH Amount'), operate:'BETWEEN'},
                        //{field: 'credit3', title: __('credit3'), operate: 'LIKE'},
                        //{field: 'credit4', title: __('credit4'), operate: 'LIKE'},
                        //{field: 'credit5', title: __('credit5'), operate: 'LIKE'},
                        //{field: 'total', title: __('total'), operate: 'LIKE'},
                        //{field: 'polatoon', title: __('Platoon arrangement'), operate: 'LIKE'},
                        //{field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        //{field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
                    {field: 'operate', title: __('Operate'), table: table, buttons: [
                           // {name: 'addcc', text: '充值', title: '充值冻结资产', icon: 'fa fa-battery', classname: 'btn btn-xs btn-primary btn-dialog',url: 'user/user/addcc'}
                           {name: 'addcc', text: '质押', title: '会员质押修改', icon: 'fa fa-battery', classname: 'btn btn-xs btn-primary btn-dialog',url: 'user/user/addcc'},
                            {name: 'referrer', text: '推荐人', title: '修改推荐人', icon: 'fa fa-user', classname: 'btn btn-xs btn-primary btn-dialog',url: 'user/user/referrer'},
                            {name: 'enable', text: '启用', title: '会员状态', icon: 'fa fa-check', classname: 'btn btn-xs btn-success btn-magic btn-ajax',url: 'user/user/enable',
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    if (row.status == "normal") {
                                        return false;
                                    }
                                    return true;
                                },
                                confirm: '确定启用吗？',
                                success: function (data, ret) {
                                    $(".btn-refresh").trigger("click");
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                            },

                            {name: 'disable', text: '禁用', title: '会员状态', icon: 'fa fa-close', classname: 'btn btn-xs btn-success btn-magic btn-ajax',url: 'user/user/disable',
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    if (row.status == "hidden") {
                                        return false;
                                    }
                                    return true;
                                },
                                confirm: '确定禁用吗？',
                                success: function (data, ret) {
                                    $(".btn-refresh").trigger("click");
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                            },
                           // {name: 'addcc', text: '归集', title: '归集', icon: 'fa fa-battery', classname: 'btn btn-xs btn-primary btn-dialog',
                           //                                 url:function (row) {
                           //                                 return "user/user/collect?ids="+row.id;
                           //
                           //                                     // $(".btn-refresh").trigger("click");
                           //                                 }},

                       ], events: Table.api.events.operate,formatter: function (value, row, index) {
                            var that = $.extend({}, this);
                            var table = $(that.table).clone(true);
                            $(table).data("operate-del", null);
                            $(table).data("operate-edit", null);
                            that.table = table;
                            return Table.api.formatter.operate.call(that, value, row, index);
                        }}
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
             Controller.api.bindevent();
        },
        addcc:function () {
            Controller.api.bindevent();
        },
        referrer:function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});